<!-- restaurant customization -->
<script type="text/javascript">

    menuHover = function() {
        var elements = document.getElementById("nav").getElementsByTagName("LI");
        for (var i=0; i<elements.length; i++) {
            elements[i].onmouseover=function() {
                this.className+="menuHover";
            }
            elements[i].onmouseout=function() {
                this.className=this.className.replace(new RegExp(" menuHover\\b"), "");
            }
        }
    }
    if (window.attachEvent) window.attachEvent("onload", menuHover);

    //--><!]]>
</script>

<?php
    if (!defined('APPPATH')) exit('No direct script access allowed');

    require_once(APPPATH.'libraries/utils/translation/class.translation.php');
    
    if(isset($_GET['lang']))
        $translate = new Translation($_GET['lang'], true);
    else {
        if(!empty($lang))
            $translate = new Translation($lang, true);
        else
            $translate = new Translation('en', true);
    }
?>

<h2><?php $translate->__('Update menu data'); ?></h2>
<form method="POST" action=<?php echo site_url() . "/admin/menu_controller/update/" . $menu_id; ?>>
    <table cellpadding="0" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th><?php $translate->__('Update menu option'); ?></th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            <?php
                if(!empty($language)) {
            ?>
                <tr>
                    <td><?php $translate->__('Language'); ?></td>
                    <td>
                        <select name="language">
                            <option value=<?php echo $language['language_id']; ?>><?php echo $language['name']; ?></option>
                            <?php
                                if(!empty($languages)) {
                                    foreach($languages as $key => $language) {
                            ?>
                                            <option value=<?php echo $language['language_id']; ?>><?php echo $language['name']; ?></option>
                            <?php
                                    }
                                }
                            ?>
                        </select>
                    </td>
                </tr>
            <?php
                }
            ?>            
            <?php
                if (!empty($menus)) {
            ?>                                                              
                <tr>
                    <td><?php $translate->__('Parent menu'); ?></td>
                    <td>
                        <select name="parent">
                            <option value="0"></option>
                            <?php
                                foreach ($menus as $key => $menu) {
                            ?>
                                    <option value=<?php echo $menu['menu_id'] ?> language=<?php echo $menu['language_id']; ?>><?php echo $menu['name'] ?></option>
                            <?php
                                }
                            ?>
                        </select>                                                              
                    </td>
                </tr>
            <?php
                }
            ?>
            <?php
                if (!empty($submenus)) {
            ?>
                <tr>
                    <td><?php $translate->__('Sub menu'); ?></td>
                    <td>
                        <select name="child">
                            <option value="0"></option>
                            <?php
                                foreach ($submenus as $key => $submenu) {
                            ?>
                                    <option value=<?php echo $submenu['menu_id'] ?> menu=<?php echo $submenu['parent_menu_id']; ?>><?php echo $submenu['name'] ?></option>
                            <?php
                                }
                            ?>
                        </select>                                                              
                    </td>
                </tr>
            <?php
                }
            ?>
            <tr>
                <td><?php $translate->__('Name'); ?></td>
                <td><input id="name" type="text" name="name" value="<?php echo $name; ?>" /></td>
            </tr>
            <!-- restaurant customization -->
            <tr>
                <td><?php $translate->__('Unified menu?'); ?></td>
                <td><input id="unionChecker" type="checkbox" name="union" value="1" /></td>
            </tr>            
            <!-- restaurant customization -->
            <tr>
                <td><?php $translate->__('Item has price?'); ?></td>
                <td><input id="priceChecker" type="checkbox" name="price" value="1" /></td>
            </tr>
            <tr id="priceBox">
                <td><?php $translate->__('Price'); ?></td>
                <td><input id="title" type="text" name="title" value="<?php echo $title; ?>" /></td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <td colspan="2">
                    <button class="btn btn-large btn-success"><?php $translate->__('Update menu'); ?></button>
                </td>
            </tr>
        </tfoot>
    </table>
</form>

<script type="text/javascript">
    function unselectedParentsHide() {
        var languageId = $('select[name="language"]').val();
        $('select[name="parent"] option').each(function() {
            if($(this).attr('language')==languageId) {
                $(this).show();
            } else {
                $(this).hide();
            }
        });
    }
    
    function unselectedChildrenHide() {
        var menuId = $('select[name="parent"]').val();
        $('select[name="child"] option').each(function() {
            if($(this).attr('menu')==menuId) {
                $(this).show();
            } else {
                $(this).hide();
            }
        });
    }
    
    function priceHide() {
        var price = $('#priceChecker').is(':checked');
        if(price) {
            $('#priceBox').show();
        } else {
            $('#priceBox').hide();
        }
    }
    
    $(document).ready(function() {
        unselectedParentsHide();
        $('select[name="language"]').change(function() {
            unselectedParentsHide();
        });
        
        unselectedChildrenHide();
        $('select[name="parent"]').change(function() {
            unselectedChildrenHide();
        });
        
        if(document.getElementById("title").value == document.getElementById("name").value)
            priceHide();
        $(':checkbox').click(function () {
            priceHide();
        });        
    });
</script>